<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>测试 VSCODE </h1>
    <input id="myname" type="text">
    <button onclick="myset()">存</button>
    <button onclick="myget()">取</button>
</body>
<script>
function myset(){
    //localStorage.setItem('stname','国服寡妇')
    //sessionStorage.setItem('stname','国服寡妇')
    let v=  document.querySelector("#myname").value
    localStorage.setItem('stname',v)
}

function myget(){
    //let v = localStorage.getItem('stname')
    let v = sessionStorage.getItem('stname')
    alert( v )
}

//网页加载事件
window.onload = function(){
    let v = localStorage.getItem('stname')
    document.querySelector("#myname").value = v
}

</script>

</html>